import os
import time
from appium import webdriver
from webdriver_manager.core.os_manager import ChromeType

from Confing import options
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from Confing import *

class Tools:


    # 向上滑动
    @classmethod
    def swipe_to_element(cls,driver):
        """
        滑动到指定元素
        :param driver: Appium Driver
        :param element: 目标元素
        :return: None
        """
        size = driver.get_window_size()
        print(size)
        start_x = size['width']*0.8
        start_y = size['height']*0.8
        end_x = start_x
        end_y = start_y * 0.3

        driver.swipe(start_x, start_y, end_x, end_y, duration=2000)


    # scroll滑动
    @classmethod
    def scroll_to_element(cls,driver,el1,el2):
        """
        滑动到指定元素
        :param driver: Appium Driver
        :param element: 目标元素
        :return: None
        """
        driver.scroll(el1,el2)

    @classmethod
    def drag_and_drop(cls, driver, el1, el2):
        """
        滑动到指定元素
        :param driver: Appium Driver
        :param element: 目标元素
        :return: None
        """
        driver.drag_and_drop(el1, el2)

    @classmethod
    def get_relative_coords(cls,driver, x_ratio, y_ratio):
        """根据屏幕比例计算实际坐标"""
        size = driver.get_window_size()
        x = int(size['width'] * x_ratio)
        y = int(size['height'] * y_ratio)
        return x, y



if __name__ == '__main__':
    driver = Tools.web_driver()
    driver.get("https://www.baidu.com")
    time.sleep(2)